//
//  LotteryListCell.m
//  MoXiProject
//
//  Created by 周筱雯 on 2017/7/17.
//  Copyright © 2017年 周筱雯. All rights reserved.
//

#import "LotteryListCell.h"
#import "LotteryModel.h"
#import "LotteryTypeModel.h"


@interface LotteryListCell ()
@property (weak, nonatomic) IBOutlet UIImageView *lotteryImg;
@property (weak, nonatomic) IBOutlet UILabel *lotteryName;
@property (weak, nonatomic) IBOutlet UILabel *lotteryqh;
@property (weak, nonatomic) IBOutlet UILabel *lotteryTime;

@property (nonatomic,strong) UILabel * annNumer;
@property (nonatomic,strong) UILabel * fernumber;
@end


@implementation LotteryListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.lotteryImg.layer.cornerRadius = self.lotteryImg.width / 2;
    self.lotteryImg.layer.masksToBounds = YES;
}
-(void) setlotteryListDataSource:(LotteryListModel *) model typeName:(NSString *)typeName typeImg:(NSString *) imageView{
    
    
    [self.lotteryImg sd_setImageWithURL:[NSURL URLWithString:imageView] placeholderImage:DEF_NORMAL_DEFAULT_IMAGE];
    [self.lotteryName setText:typeName];
    
    [self.lotteryqh setText:[NSString stringWithFormat:@"第%@期",model.listissueno]];
    [self.lotteryTime setText:[MXUtility getTimeWithTimestamp:model.listopendate WithDateFormat:@"yyyy-MM-dd"]];
    
    /**
     开奖号码
     */
    NSString *string = model.listnumber;
    NSArray *aArray = [string componentsSeparatedByString:@" "];
    
    
    for (int i=0; i<aArray.count; i++) {
        if (IPHONE5) {
            self.annNumer = [[UILabel alloc]initWithFrame:CGRectMake(71+25*i, 54, 20, 20)];
        }else{
            self.annNumer = [[UILabel alloc]initWithFrame:CGRectMake(71+35*i, 54, 30, 30)];
        }        [self.annNumer setTextAlignment:NSTextAlignmentCenter];
        [self.annNumer setFont:[UIFont systemFontOfSize:12.f]];
        self.annNumer.textColor = [UIColor whiteColor];
        self.annNumer.text = [NSString stringWithFormat:@"%d",[aArray[i] intValue]];
        self.annNumer.layer.cornerRadius = self.annNumer.width / 2;
        self.annNumer.layer.masksToBounds =  YES;
        [self addSubview:self.annNumer];
        [self.annNumer setBackgroundColor:DEF_COLOR_MAINCOLOR_LOTTERY];
    }

    
    /**
     参考号
     */
    NSString * fernumber = model.listrefernumber;
    NSArray *fArray = [fernumber componentsSeparatedByString:@" "];

    for (int i=0; i<fArray.count; i++) {
        
        if (IPHONE5) {
            self.fernumber = [[UILabel alloc]initWithFrame:CGRectMake((self.annNumer.x + self.annNumer.width + 10)+25*i, 54, 20, 20)];
            
        }else{
            self.fernumber = [[UILabel alloc]initWithFrame:CGRectMake((self.annNumer.x + self.annNumer.width + 10)+35*i, 54, 30, 30)];
        }        [self.fernumber setTextAlignment:NSTextAlignmentCenter];
        self.fernumber.textColor = [UIColor whiteColor];
        [self.fernumber setFont:[UIFont systemFontOfSize:12.f]];
        self.fernumber.text = [NSString stringWithFormat:@"%d",[fArray[i] intValue]];
        self.fernumber.layer.cornerRadius = self.fernumber.width / 2;
        self.fernumber.layer.masksToBounds =  YES;
        [self addSubview:self.fernumber];
        [self.fernumber setBackgroundColor:DEF_COLOR_0080FF];
    }
}

-(void) setlotteryType:(LotteryTypeModel *) type{
    

    [self.lotteryImg sd_setImageWithURL:[NSURL URLWithString:type.typeimgUrl] placeholderImage:DEF_NORMAL_DEFAULT_IMAGE];
    [self.lotteryName setText:type.typelotteryTypeName];

    [self.lotteryqh setText:[NSString stringWithFormat:@"第%@期",type.typeqihao]];
    [self.lotteryTime setText:[MXUtility getTimeWithTimestamp:type.typedateline WithDateFormat:@"yyyy-MM-dd"]];
    
    /**
     开奖号码
     */
    NSString *string = type.typenumberlf;
    NSArray *aArray = [string componentsSeparatedByString:@","];
    
    
    for (int i=0; i<aArray.count; i++) {
        if (IPHONE5) {
            self.annNumer = [[UILabel alloc]initWithFrame:CGRectMake(71+25*i, 54, 20, 20)];
        }else{
            self.annNumer = [[UILabel alloc]initWithFrame:CGRectMake(71+35*i, 54, 30, 30)];
        }
        [self.annNumer setTextAlignment:NSTextAlignmentCenter];
        [self.annNumer setFont:[UIFont systemFontOfSize:12.f]];
        self.annNumer.textColor = [UIColor whiteColor];
        self.annNumer.text = [NSString stringWithFormat:@"%d",[aArray[i] intValue]];
        self.annNumer.layer.cornerRadius = self.annNumer.width / 2;
        self.annNumer.layer.masksToBounds =  YES;
        [self addSubview:self.annNumer];
        [self.annNumer setBackgroundColor:DEF_COLOR_MAINCOLOR_LOTTERY];
    }

    /**
     参考号
     */
    NSString * fernumber = type.typenumberrt;
    NSArray *fArray = [fernumber componentsSeparatedByString:@","];
    
    for (int i=0; i<fArray.count; i++) {
        if (IPHONE5) {
            self.fernumber = [[UILabel alloc]initWithFrame:CGRectMake((self.annNumer.x + self.annNumer.width + 10)+25*i, 54, 20, 20)];

        }else{
            self.fernumber = [[UILabel alloc]initWithFrame:CGRectMake((self.annNumer.x + self.annNumer.width + 10)+35*i, 54, 30, 30)];
        }
        [self.fernumber setTextAlignment:NSTextAlignmentCenter];
        self.fernumber.textColor = [UIColor whiteColor];
        [self.fernumber setFont:[UIFont systemFontOfSize:12.f]];
        self.fernumber.text = [NSString stringWithFormat:@"%d",[fArray[i] intValue]];
        self.fernumber.layer.cornerRadius = self.fernumber.width / 2;
        self.fernumber.layer.masksToBounds =  YES;
        [self addSubview:self.fernumber];
        [self.fernumber setBackgroundColor:DEF_COLOR_0080FF];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
